<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/reset.css"/>
		<style type="text/css">
			.father{
				left: 50%;
				transform: translateX(-50%);
				position: relative;
				width: 790px;
				height: 340px;
				overflow: hidden;
			}
			ul{
				width: 999999px;
				height: 340px;		
				transition:all 1s;		
			}
			li{
				display: inline-block;
				width: 790px;
				height: 340px;
			}
			img{
				width: 790px;
				height: 340px;
			}
			#left,#right{
				position: absolute;
				width: 150px;
				height: 340px;
				background:rgba(0,0,0,.2);
				font-size: 30px;
				text-align: center;
				line-height: 340px;
				top: 0;
				z-index: 999;
			}
			#left{
				left: 0;
			}
			#right{
				right: 0;
			}
		</style>
	</head>
	<body>		
		<div class="father">
			<div id="left">向左</div>
			<ul>
				<li><img src="img/campIcon_01.jpg" alt="" /></li>
				<li><img src="img/campIcon_02.jpg" alt="" /></li>
				<li><img src="img/campIcon_03.jpg" alt="" /></li>
				<li><img src="img/campIcon_04.jpg" alt="" /></li>
			</ul>
			<div id="right">向右</div>
		</div>	
		<script type="text/javascript">
			var left=document.getElementById('left');
			var right=document.getElementById('right');
			var ul=document.getElementsByTagName('ul')[0];
			var li=document.querySelectorAll('li');
			var width=li[0].offsetWidth;
			var colne=li[0].cloneNode(true);
			ul.appendChild(colne);		
			var i=0;//当前索引
			right.addEventListener('click',go_right);
			function go_right(){
				if(i==li.length-1){					
					i=0;					
				}
				else{
					i++;
				}				
				ul.style.transform='translate('+(-(i*width))+'px)';
			}
			colne.addEventListener('transitionend',function(){
				//在复制完成后，瞬间回到第一张
				if(i==li.length-1){
					ul.style.animationDirection=0;
				}
			})
		</script>
	</body>
</html>
